<?php
require_once '../app/core/services/BaseService.php';
require_once '../app/models/DeliveryInfoDao.php';

class DeliveryService extends BaseService {
	private $deliveryInfoDao;
	
    public function __construct(){
		parent::__construct();
		
		$this->deliveryInfoDao = new DeliveryInfoDao($this->dbUtil);
	}
	
	public function saveDelivery($param){
		return $this->deliveryInfoDao->saveDelivery($param);
	}
	
	public function updateDelivery($param){
		 $this->deliveryInfoDao->updateDelivery($param);
	}
	
	public function getDeliveryList($userId){
	    
		$deliveries = $this->deliveryInfoDao->getDeliveriesOfUser($userId);
		$deliveryArr = array();
		if($deliveries){
			$areaService = new AreaService();
			
		    foreach($deliveries as $delivery){
		    	$province = $areaService->getAreaById($delivery['address_1']);
		        $deliveryArr[$delivery['id']]['province'] = $province[0]['title'];
		        $city = $areaService->getAreaById($delivery['address_2']);
		        $deliveryArr[$delivery['id']]['city'] = $city[0]['title'];
		        $county = $areaService->getAreaById($delivery['address_3']);
		        $deliveryArr[$delivery['id']]['county'] = $county[0]['title'];
		    }
		}
		return array($deliveries,$deliveryArr);
	}
	
	public function getDeliveryById($deliveryId){
		return $this->deliveryInfoDao->getDeliveryById($deliveryId);
	}
	
	public function delDelivery($deliveryId){
		$this->deliveryInfoDao->delDelivery($deliveryId);
	}
	
	public function getAddressNumByUserId($userId){
		return $this->deliveryInfoDao->getAddressNumByUserId($userId);
	}
		
}
?>